/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.util.ArrayList;
import model.Nhasanxuat;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import util.HibernateUtil;

/**
 *
 * @author HoangLiem
 */
public class NhaSanXuatDAO {
    public static ArrayList<Nhasanxuat> getAll() {
        ArrayList<Nhasanxuat> list = null;
        try {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            Transaction trans = session.getTransaction();
            trans.begin();
            String hql = "from Nhasanxuat nsx";
            Query query = session.createQuery(hql);
            list = (ArrayList<Nhasanxuat>)query.list();
            trans.commit();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return list;
    }
     public static Nhasanxuat getManufacturerById(String maNSX) {
        Nhasanxuat nsx = null;
        try {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            Transaction trans = session.getTransaction();
            trans.begin();
            String hql = "from Nhasanxuat nsx where nsx.maNhaSanXuat=:maNSX";
            Query query = session.createQuery(hql);
            query.setString("maNSX", maNSX);
            nsx =(Nhasanxuat)query.uniqueResult();
            trans.commit();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return nsx;
    }
}
